package com.tianpengtech.common.validator.rules.string;

import org.apache.commons.lang.StringUtils;

import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.validator.AbstractRule;


public class StringLengthBetween extends AbstractRule {

    private int min;
    private int max;

    public StringLengthBetween(String v, String msg, int min, int max) {
        this.value = v;
        this.msg = msg;
        this.min = min;
        this.max = max;
    }

    @Override
    public boolean validate() throws ValidateException {
        String v = StringUtils.trim((String) this.value);
        if (StringUtils.length(v) < this.min || StringUtils.length(v) > this.max) {
            throw new ValidateException(this.msg);
        }
        return true;
    }
}
